package com.fyd.mybatis.session;

import com.fyd.mybatis.binding.MapperRegistry;
import com.fyd.mybatis.mapping.MappedStatement;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: fyd20
 * @Date: 2025/6/4 19:01
 * @Description: 配置项
 * @Version 1.0.0
 */
public class Configuration {
    protected MapperRegistry mapperRegistry = new MapperRegistry(this);
    protected final Map<String, MappedStatement> mappedStatements = new HashMap<>();
    public void addMappers(String packageName){
        mapperRegistry.addMappers(packageName);
    }
    public <T> void addMapper(Class<T> type){
        mapperRegistry.addMapper(type);
    }
    public <T> T getMapper(Class<T> type, SqlSession sqlSession){
        return mapperRegistry.getMapper(type,sqlSession);
    }

    public boolean hasMapper(Class<?> type){
        return mapperRegistry.hasMapper(type);
    }

    public void addMappedStatement(MappedStatement ms){
        mappedStatements.put(ms.getId(),ms);
    }

    public MappedStatement getMappedStatement(String id){
        return mappedStatements.get(id);
    }
}
